package com.abaaba.project2.controller.wxcontroller;

import com.abaaba.project2.bean.bo.WxAddressBo;
import com.abaaba.project2.bean.bo.WxAddressDeleteBo;
import com.abaaba.project2.bean.vo.BaseRespVo;
import com.abaaba.project2.bean.vo.WxAddressDetailVo;
import com.abaaba.project2.bean.vo.WxAddressVo;
import com.abaaba.project2.service.wx.WxAddressService;
import com.abaaba.project2.util.UserIdUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/wx/address")
public class WxAddressController {

    @Autowired
    WxAddressService wxAddressService;

    @RequestMapping("/list")
    public BaseRespVo getAddressList() {
        System.out.println("userId = " + UserIdUtil.getUserId());

        List<WxAddressVo> wxAddressVos = wxAddressService.getAddressList(UserIdUtil.getUserId());
        return BaseRespVo.ok(wxAddressVos);
    }

    @RequestMapping("/detail")
    public BaseRespVo getAddressDetail(Integer id) {
        WxAddressDetailVo wxAddressDetailVo = wxAddressService.getAddressDetail(id);
        return BaseRespVo.ok(wxAddressDetailVo);
    }

    /**
     * 修改、新建
     */
    @RequestMapping("/save")
    public BaseRespVo saveAddress(@RequestBody WxAddressBo address) {

        Integer affectedRows = wxAddressService.saveAddress(address, UserIdUtil.getUserId());
        return BaseRespVo.ok();
    }

    @RequestMapping("/delete")
    public BaseRespVo deleteAddress(@RequestBody WxAddressDeleteBo wxAddressDeleteBo) {
        Integer affectedRows = wxAddressService.deleteAddress(wxAddressDeleteBo.getId());
        return BaseRespVo.ok();
    }
}
